package com.PGD.events
{
	import com.PGD.model.vos.ISlide;
	import com.PGD.model.vos.ISlidePack;
	
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;

	public class SlidePackEvent extends Event
	{
		
		
		public static const UPDATE_DB:String = "updateDb";
		
		
		public var slidePack:ISlidePack;
		public var deletedSlides:ArrayCollection;
		
		public function SlidePackEvent(type:String)
		{
			super(type, true, false);
		}
		
		
		public function get dto():ISlidePack
		{
			var toSend:ISlidePack = slidePack.clone() as ISlidePack;
			toSend.lastSaved = new Date();
			var counter:int = 0;
			var slidesToPersist:ArrayCollection = new ArrayCollection;
			for each(var slide:ISlide in slidePack.slides)
			{
				
				counter++;
				//verify order has not been changed;
				if(slide.timecode != counter){
				trace(slide.timecode+" order is diff "+counter)
				slide.timecode = counter;	
			
				slide.isDirty = true};
				slide.timecode = counter;	
				if(slide.needToPersist)
				{
					slidesToPersist.addItem(slide);
				}
			}
			toSend.slides = slidesToPersist;
			return toSend;
		}
		
		
		
	}
}